var express = require('express');
var router = express.Router();
var app = express();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

// data:JSON.stringify({'a':'1','b':'2'})
router.get('*',function(req,res,next){
  res.header('Access-Control-Allow-Origin','*');
  res.header('Access-Control-Allow-Headers','Content-Type');
  res.header('Access-Control-Allow-Methods','*');
  res.header('Content-Type','application/json;charset=utf-8');
  next();
})

router.get('/home',function(req,res,next){
  res.json({
    code:200,
    data:{
      name:'dw',
      age:18
    },
    msg:"请求成功"
  })
})

router.get('/list',function(req,res,next){
  res.json({
    code: 200,
    data:[{
      id:'01',
      name:'html5',
      value:'01'
    },
    {
      id:'02',
      name:'css3',
      value:'02'
    },
    {
      id:'03',
      name:'js',
      value:'03'
    }],
    msg:'保存成功'
  })
})

app.post('/save',function(req,res,next){
  res.json({
    code: 200,
    data:{},
    msg:'保存成功'
  })
})

module.exports = router;
